package com.hpf.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @description: 消息消费者
 * @datetime: 2020/10/25 16:34
 * @author: huangpengfei
 */
@Component
@EnableBinding(Sink.class)
@Slf4j
public class StreamMessageListenerController {

    @Value("${server.port}")
    private String serverPort;

    /**
     * 消费消息
     * @param message: 接收消息
     * @return java.lang.String
     * @author  huangpengfei
     * @datetime  2020/10/25 16:37
     */
    @StreamListener(Sink.INPUT)
    public void consumer(Message<String> message){
        System.out.println("消费者2号接收的消息：" + message.getPayload() + "\t 端口：" + serverPort);
    }
}
